<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>怀才教育</title>
    <meta content="怀才教育是一个专门做教育软件的科技公司" name="descriptison">
    <meta content="怀才教育" name="keywords">

    <!-- Favicons -->
    <link href="/upload/1/platform/20230515/logo.simple.png" rel="icon">
    <link href="/upload/1/platform/20230515/logo.simple.png" rel="apple-touch-icon">

    <!-- Vendor CSS Files -->
    <link href="/upload/1/platform/20230515/bootstrap.min.css" rel="stylesheet">
    <link href="/upload/1/platform/20230515/icofont.min.css" rel="stylesheet">
    <link href="/upload/1/platform/20230515/aos.css" rel="stylesheet">
    <link href="/upload/1/platform/20230515/line-awesome.min.css" rel="stylesheet">
    <link href="/upload/1/platform/20230515/owl.carousel.min.css" rel="stylesheet">
    <link href="/upload/1/platform/20230515/style.css" rel="stylesheet">


</head>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0-0/axios.min.js"></script>
<script src="/upload/1/platform/20230515/jquery.min.js"></script>
<script src="/upload/1/platform/20230515/bootstrap.bundle.min.js"></script>

<body>
    <!-- ======= Mobile Menu ======= -->
    <div class="site-mobile-menu site-navbar-target">
        <div class="site-mobile-menu-header">
            <div class="site-mobile-menu-close mt-3">
                <span class="icofont-close js-menu-toggle"></span>
            </div>
        </div>
        <div class="site-mobile-menu-body"></div>
    </div>

    <!-- ======= Header ======= -->
    <div class="site-navbar js-sticky-header site-navbar-target" role="banner">

        <div class="container">
            <div class="row align-items-center">

                <div class="col-6 col-lg-2" style="padding-left: 0px; padding-right: 0px;">
                    <h1 class="mb-0 site-logo"><a href="index" style="text-decoration:none" class="mb-0">
                            <img src="" style="max-height: 80px;" alt="">
                            怀才教育</a>
                    </h1>
                </div>

                <div class="col-12 col-md-10 d-none d-lg-block">
                    <nav class="site-navigation position-relative text-right" role="navigation">

                        <ul class="site-menu main-menu js-clone-nav mr-auto d-none d-lg-block">
                            <li class="active"><a href="index" class="nav-link">首页</a></li>
                            <li class="has-children">
                                <a style="cursor: pointer;" href="blog.html" class="nav-link">在线编程</a>
                                <ul style="cursor: pointer;" class="dropdown">
                                    <li><a href="/scratch3" class="nav-link">Scratch3编辑器</a></li>
                                </ul>
                            </li>

                            <li><a style="cursor: pointer;" href="courseList" class="nav-link">课程列表</a></li>
                            <li><a style="cursor: pointer;" href="certQuery" class="nav-link">证书查询</a></li>
                            <li><a style="cursor: pointer;" href="docs" class="nav-link">资料下载</a></li>
                            <li class="has-children">
                                <a style="cursor: pointer;" class="nav-link">新闻</a>
                                <ul class="dropdown">
                                    <li><a href="newsList?kind=1" class="nav-link">行业新闻</a></li>
                                    <li><a href="newsList?kind=2" class="nav-link">我的新闻</a></li>
                                    <li><a href="newsList?kind=3" class="nav-link">竞赛活动</a></li>
                                </ul>
                            </li>
                            <li id="aboutus"><a href="aboutus" class="nav-link">关于我们</a></li>
                            <span> </span>
                            <span> </span>

                            <li id="userInfoBar"> </li>
                        </ul>

                    </nav>
                </div>

                <div class="col-6 d-inline-block d-lg-none ml-md-0 py-3" style="position: relative; top: 3px;">

                    <a href="#" class="burger site-menu-toggle js-menu-toggle">
                        <span></span>
                    </a>
                </div>

            </div>
        </div>

    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">
                        登录
                    </h4>
                </div>

                <div class="container">
                    <div class="row " style="margin:20px">
                        <div class="col-xs-4 col-md-4">手机号码: </div>
                        <div class="col-xs-8 col-md-8"> <input type="text" id="tel"></div>
                    </div>
                    <div class="row" style="margin:20px" id="pswdUI">
                        <div class="col-xs-4 col-md-4">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码: </div>
                        <div class="col-xs-8 col-md-8"> <input type="password" id="pswd"></div>
                    </div>
                    <div class="row" style="margin:20px; display: none;" id="rePswdUI">
                        <div class="col-xs-4 col-md-4">密码确认:</div>
                        <div class="col-xs-8 col-md-8"> <input type="password" id="repswd"></div>
                    </div>
                    <div class="row" style="margin:20px; display: none;" id="yanzhengmaUI">
                        <div class="col-xs-4 col-md-4">验证码:</div>
                        <div class="col-xs-3 col-md-3"> <input type="text" style="width: 100px;" placeholder="请输入验证码"
                                id="yanzhengma">
                        </div>
                        <div class="col-xs-5 col-md-5"> <button class="btn btn-info"
                                style="padding: 4px 10px !important; margin-left: 20px;" onclick="getCaptcha()"> 验证码
                            </button></div>
                    </div>
                    <div class="row" style="margin:20px">
                        <div class="col-xs-4 col-md-4"><button type="button" class="btn btn-warning" onclick="clear()">
                                清除 </button> </div>
                        <div class="col-xs-4 col-md-4"> </div>
                        <div class="col-xs-4 col-md-4"> <button type="button" class="btn btn-primary"
                                onclick="onSubmitHandler()"> 确定
                            </button> </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <div class="row" style="margin:20px">
                        <div class="col-xs-4" style="margin-left:20px;" id="gotoForgetPSWD" onclick="setPopStatus(2)">
                            忘记密码？ </div>
                        <div class="col-xs-4" style="margin-left:20px;display: none;" id="gotoLogin"
                            onclick="setPopStatus(0)">去登录</div>
                        <div class="col-xs-4" style="margin-left:20px;" id="gotoRegister" onclick="setPopStatus(1)">
                            立即注册! </div>
                    </div>


                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    <!-- 重置密码 -->
    <div class="modal fade" id="setPswdModal" tabindex="-1" role="dialog" aria-labelledby="setPswdModalLabel"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="setPswdModalLabel">
                        重置密码
                    </h4>
                </div>

                <div class="container">
                    <div class="row" style="margin:20px" id="pswdUI">
                        <div class="col-xs-4 col-md-4">原密码: </div>
                        <div class="col-xs-8 col-md-8"> <input type="password" id="oldpswd"></div>
                    </div>
                    <div class="row" style="margin:20px" id="pswdUI">
                        <div class="col-xs-4 col-md-4">新密码: </div>
                        <div class="col-xs-8 col-md-8"> <input type="password" id="newpswd"></div>
                    </div>
                    <div class="row" style="margin:20px;" id="rePswdUI">
                        <div class="col-xs-4 col-md-4">密码确认:</div>
                        <div class="col-xs-8 col-md-8"> <input type="password" id="resetRepswd"></div>
                    </div>



                </div>
                <div class="modal-footer">
                    <div class="row" style="margin:20px">
                        <div class="col-xs-4" style="margin-left:20px;">
                            <button type="button" class="btn btn-primary" onclick="resetPswd()"> 确定
                            </button> </div>

                    </div>


                </div>
            </div><!-- /.modal-content -->
        </div>
    </div>
    <script>
        var isRegisger = false;
        var popStatus = 0;//0 是登录.1是注册.2 是忘记密码
        function openRegLoginPanel() {
            $('#myModal').modal('show');
            zhezhao = document.getElementsByClassName("modal-backdrop");
            if (zhezhao && zhezhao.length > 0) {
                document.body.removeChild(zhezhao[0]);
            }
        }
        function clear() {
            document.getElementById("tel").value = "";
            document.getElementById("pswd").value = "";
            document.getElementById("repswd").value = "";

        }
        function setPopStatus(newStatus) {

            popStatus = newStatus;
            switch (popStatus) {
                case 0:
                    document.getElementById("myModalLabel").innerHTML = "登录";
                    document.getElementById("gotoLogin").setAttribute("style", "display:none;margin-left:20px;");
                    document.getElementById("gotoRegister").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("gotoForgetPSWD").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("rePswdUI").setAttribute("style", "display:none;margin:20px; ");
                    document.getElementById("yanzhengmaUI").setAttribute("style", "display:none; ");

                    break;
                case 1:
                    document.getElementById("myModalLabel").innerHTML = "注册";
                    document.getElementById("gotoRegister").setAttribute("style", "display:none;margin-left:20px;");
                    document.getElementById("gotoLogin").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("gotoForgetPSWD").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("rePswdUI").setAttribute("style", "margin:20px; ");
                    document.getElementById("yanzhengmaUI").setAttribute("style", "margin:20px; ");


                    break;
                case 2:
                    document.getElementById("myModalLabel").innerHTML = "忘记密码";
                    document.getElementById("gotoForgetPSWD").setAttribute("style", "display:none;margin-left:20px;");
                    document.getElementById("gotoRegister").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("gotoLogin").setAttribute("style", "display:block;margin-left:20px;");
                    document.getElementById("rePswdUI").setAttribute("style", "display:none;margin:20px; ");
                    document.getElementById("pswdUI").setAttribute("style", "display:none;margin:20px; ");
                    document.getElementById("yanzhengmaUI").setAttribute("style", "margin:20px; ");

                    break;

                default:
                    break;
            }
        }
        function resetPswd() {

            if (document.getElementById("newpswd").value.length < 6) {

                alert("密码必须大于6位数")
                return;
            }
            if (document.getElementById("resetRepswd").value != document.getElementById("newpswd").value) {

                alert("重复密码不对")
                return;
            }
            var oldpswd = md5(document.getElementById("newpswd").value);
            var newpswd = md5(document.getElementById("oldpswd").value);
            axios.put('/api/student/updateMyPSWD?oldpswd=' + oldpswd + '&newpswd=' + newpswd, "", {
                headers: {
                    'token': sessionStorage.getItem("token")
                },

            })
                .then(function (response) {
                    var res = response.data;
                    if (res.code != 200) {

                        alert(res.title)
                        return;
                    }

                    $('#setPswdModal').modal('hide');
                    alert("修改成功")

                });


        }
        function onSubmitHandler() {
            if (document.getElementById("tel").value.length < 10) {

                alert("电话号码必须11位")
                return;
            }
            switch (popStatus) {
                case 0:
                    if (document.getElementById("pswd").value.length < 6) {

                        alert("密码必须6位以上")
                        return;
                    }
                    login();
                    break;
                case 1:
                    if (document.getElementById("pswd").value.length < 6) {

                        alert("密码必须6位以上")
                        return;
                    }
                    if (document.getElementById("yanzhengma").value.length < 4) {

                        alert("验证码不对")
                        return;
                    }
                    register();
                    break;
                case 2:
                    forgetPswd();
                    break;

                default:
                    break;
            }
        }
        function login() {

            var loginObj = {};
            loginObj.tel = document.getElementById("tel").value;
            loginObj.password = md5(document.getElementById("pswd").value);

            axios.post('/api/student/login', loginObj)
                .then(function (response) {
                    var res = response.data;
                    if (res.code != 200) {

                        alert(res.title)
                        return;
                    }
                    sessionStorage.setItem("token", res.title);
                    sessionStorage.setItem("userID", res.data.id);
                    sessionStorage.setItem("userName", res.data.Username);
                    $('#myModal').modal('hide');
                    window.location.reload();
                });
        }

        function getCaptcha() {

            axios.post('/api/student/captcha?tel=' + document.getElementById("tel").value)
                .then(function (response) {
                    var res = response.data;
                    alert(res.title)


                });
        }
        function register() {
            axios.post('/api/student/register?password=' + document.getElementById("pswd").value + "&tel=" + document.getElementById("tel").value + "&captcha=" + document.getElementById("yanzhengma").value)
                .then(function (response) {
                    var res = response.data;
                    if (res.code != 200) {
                        alert(res.title)
                        return;
                    }
                    sessionStorage.setItem("token", res.title);
                    $('#myModal').modal('hide');
                    window.location.reload();

                });
        }
        function openResetPswd() {
            $('#setPswdModal').modal('show');
            zhezhao = document.getElementsByClassName("modal-backdrop");
            if (zhezhao && zhezhao.length > 0) {
                document.body.removeChild(zhezhao[0]);
            }
        }
        function forgetPswd() {
        }
        function gotoUserCenter() {
            window.location.href = "/user"
        }
        function logOut() {
            var r = confirm("确定退出？")
            if (r == true) {
                sessionStorage.removeItem("token");
                sessionStorage.removeItem("userID");
                sessionStorage.removeItem("userName");
                window.location.href = "/"
            }

        }


        function checkLogin() {

            if (sessionStorage.getItem("token")) {
                document.getElementById("userInfoBar").outerHTML = ` <li class="has-children">
                    <a class="nav-link  "  style="cursor:pointer"   onclick="gotoUserCenter()" >个人中心</a>
                                <ul class="dropdown"> 
                                    <li><a onclick="gotoUserCenter()" class="nav-link">个人中心</a></li> 
                                    <li><a onclick="openResetPswd()" class="nav-link">修改密码</a></li> 
                                    <li><a onclick="logOut()" class="nav-link">退出登录</a></li> 
                                </ul>
                            </li>
                            `;
            } else {
                document.getElementById("userInfoBar").innerHTML = '<a class="nav-link " id="regBt" style="cursor:pointer"  onclick="openRegLoginPanel()" >注册 / 登录</a>';

            }
        }
        checkLogin();

    </script>